<?php

require_once( '../../libs/smarty.inc' );
require_once( '../../libs/smt_variables.php' );
require_once( '../../libs/Class_DB.php' );
require_once( '../../libs/Class_ERROR.php' );
require_once( '../../libs/login.inc.php' );

if( !in_array( "N", $_SESSION['ADMIN_LOGIN']['AUTH_CD'] ) ) exit;

if( $_SERVER['REQUEST_METHOD'] == 'GET'){	
	$mod = $_GET['mod'];
	if($mod =='delete'){
		$order_id = $_GET['order_id'];
		$db = new Class_DB;
		$sql = "DELETE FROM k_order_head WHERE order_id = '$order_id'";
		$result = $db ->query($sql);
		$smarty->assign('phase', 'complete');
	}
	else if($mod =='copy'){
		$order_id = $_GET['order_id'];
		/*
		$date = Date("Y/m/d");
		$o_status = 0;
		$m_status = 0;
		$delivery_order = 0;
		$email_status = 0;
		$sale_status = 0;
		$dateno = date('Ymd');
		$db = new Class_DB;
		$noSql = "SELECT * FROM k_order_head WHERE order_id like '%".$dateno."%' order by order_id desc limit 0,1";
		$result = $db->query($noSql);
		$row = mysql_fetch_array($result);
		if(!empty($row['order_id'])){
			$strPrice_no = substr($row['order_id'],strlen($row['order_id'])-3,strlen($row['order_id']))+1;
			if(strlen($strPrice_no) == 1){
				$row['order_id'] = $dateno."00".$strPrice_no;
			}elseif (strlen($strPrice_no) == 2){
				$row['order_id'] = $dateno."0".$strPrice_no;
			}else{
				$row['order_id'] = $dateno.$strPrice_no;
			}
				
		}else{
			$row['order_id'] = $dateno."001";
		}
		$order_id = $row['order_id'];
		$oid = $_GET['order_id'];
		
		$sql = "INSERT INTO k_order_head (order_id,category,comtype,name,kana,email,phone,fax,zip,pofuse,pofuse_info,delivery_date,
		delivery_zip,delivery_address,delivery_phone,delivery_contact,delivery_contact_info,hope_date,print_use,
		wherefrom,wherefrom_info,pay_type,special,remark,m_date,u_date,o_date,o_status,m_status,delivery_order,
		email_status,sale_status,staff_id,address) select '$order_id',category,comtype,name,kana,email,phone,fax,zip,pofuse,pofuse_info,delivery_date,
		delivery_zip,delivery_address,delivery_phone,delivery_contact,delivery_contact_info,hope_date,print_use,
		wherefrom,wherefrom_info,pay_type,special,remark,'$date','$date','$date',o_status,m_status,delivery_order,
		email_status,sale_status,staff_id,address from k_order_head where order_id='$oid'";
		
		$phase = 'completecopy';
		$smarty->assign('phase', $phase);
		$smarty->assign('order_id', $order_id);
		*/
		header("Location: order.php?order_id=$order_id&mod=copy");
		exit();
		
	}
	else{
	
		$order_id = $_GET['order_id'];
		$db = new Class_DB;
		$sql = "SELECT * FROM k_order_head WHERE order_id = '$order_id'";
		$result = $db ->query($sql);
		$row = mysql_fetch_array($result);
		$pofusearray = unserialize($row['pofuse']);
		$pofuse = "";
		if($pofusearray[0]==1) $pofuse .= "作品展　";
		if($pofusearray[1]==2) $pofuse .= "コンテスト募集　";
		if($pofusearray[2]==3) $pofuse .= "個人所有や贈与品　";
		if($pofusearray[3]==4) $pofuse .= "その他:".$row['pofuse_info'];
		$row['pofuse']=$pofuse;
		
		$printusearray = unserialize($row['print_use']);
		$printuse = "";
		if($printusearray[0]==1) $printuse .= "初めて　";
		if($printusearray[0]==2) $printuse .= "利用したことがある　";
		if($printusearray[1]!='') $printuse .= $printusearray[1]."年　";
		if($printusearray[2]!='') $printuse .= $printusearray[2]."月頃　";
		$row['printuse']=$printuse;
		
		$wherefromarray = unserialize($row['wherefrom']);
		$wherefrominfoarray = unserialize($row['wherefrom_info']);
		$wherefrom = "";
		if($wherefromarray[0]==1) $wherefrom .= "HP　";
		if($wherefromarray[1]==2) $wherefrom .= "雑誌　";
		if($wherefromarray[2]==3) $wherefrom .= "友人紹介:".$wherefrominfoarray[0];
		if($wherefromarray[3]==4) $wherefrom .= "その他:".$wherefrominfoarray[1];
		$row['wherefrom']=$wherefrom;
		$row['special']=nl2br($row['special']);
		$row['remark']=nl2br($row['remark']);
		
		$row['m_date']=date('Y/m/d',strtotime($row['m_date']));
		$row['u_date']=date('Y/m/d',strtotime($row['u_date']));
		$row['o_date']=date('Y/m/d',strtotime($row['o_date']));
		$row['delivery_date']=$row['delivery_date']==NULL?"":date('Y/m/d',strtotime($row['delivery_date']));
		$row['hope_date']=$row['hope_date']==NULL?"":date('Y/m/d',strtotime($row['hope_date']));
		$smarty->assign('order', $row);
		
	}
}

$menu_html = file_get_contents( $_SERVER['DOCUMENT_ROOT'].'/templates/web-admin/menu.html' );

$smarty->assign('menu_html', $menu_html);

$smarty->display('web-admin/orderInfo.html');


?>